<?php

class member extends Model
{
	
  var $name = 'Member';
  var $primaryKey = 'member_id';
  var $belongsTo = 'Producer';
  
	var $first_name;
	var $member_id;
	var $last_name;
	var $first_name_2;
	var $last_name_2; 
	var $business_name;
	var $address_line1;
	var $address_line2;
	var $city;
	var $state;
	var $password;
	var $zip;
	var $work_address_line1;
	var $work_address_line2;
	var $work_city;
	var $work_state;
	var $work_zip;
	var $email_address;
	var $email_address_2;
	var $home_phone;
	var $work_phone;
	var $mobile_phone;
	var $fax;
	var $mem_taxexempt; 
	var $deltype;
	var $hub;
	var $truck_code;
	var $delcode_id;
	var $basket_id;
	var $membership_date;
	var $toll_free;
	var	$home_page;
	var	$pub_address;
	var	$pub_email;
	var	$pub_email2;
	var	$pub_phoneh;
	var	$pub_phonew;
	var	$pub_phonec;
	var	$pub_phonet;
	var	$pub_fax;
	var	$pub_web;
	var $finalized;
	var $ddeltype;
	var $rte_confirmed;
	var $prod_sum;
	var $username_m;
	var $adj_id;
	var $how_heard_id;
	var $auth_type;
		
	
	
	function member(){
		$args=func_get_args();//$Argument=null doesn't work in a constructor in this version of PHP4
		if($args[0]){
			$this->set($args[0]);
		}
		
    $this->__construct();
    
	}
	
	//retrieve member info by id, set the member to the info
	function setById($member_id){
			
		$sql = "SELECT * FROM ".TABLE_MEMBER." WHERE member_id=$member_id";
		
		$query = mysql_query($sql, MYSQL_CONN) or die(STANDARD_ERROR.mysql_error());
		
		$row = mysql_fetch_array($query);
		
		$this->set($row);
		
		return true;	
	}
	
	//set data members to an sql result.  Must have all the data members
	function set($row, $string_keys_only=null){
		
		$dataMembers = get_object_vars($this);
		$i = 0;
		reset($row);
		
		//this loop is a quasi-hack. What's going on is that in certain joins, PHP won't be able to figure how to create an associative key with the name of field, as in member_id here since there are 3.  Using mysql_fetch_array()with no second argument we get indices followed by keys, in order, in the array.  The value, of member_id here, will always be assigned to its numeric index.  So this assigns only the associative keys to their respective member and if for some reason nothing came of, it moves back to the index for the key and looks for the value there. I don't think there's anythin for it but to make long lists otherwise.
		for($i=0;$i<count($row);$i++){
			$key = key($row);
			if(gettype($key)=="string"){
				if(isset($row[$key])){
					$this->$key=$row[$key];
				}elseif(!$string_keys_only){
					prev($row);
					$index = key($row);
					$this->$key=$row[$index];
					next($row);
				}elseif($string_keys_only){
					$this->$key = NULL;
				}
			}
			next($row);
							
		}
				
		return true;
	}

	//puts together a block of name info to show, the optional variable reverse switches some stuff up	
	function showName($reverse=null){
				
		if($this->business_name=="$this->first_name $this->last_name"){
			return '  <span class="fn org">' . $this->business_name . "</span>";
		}
		
		if($this->business_name && !$reverse){
			$show_name='  <span class="org">' . $this->business_name . "</span>\n";
		}
		
		if(($this->first_name || $this->last_name) && !$reverse){
			$show_name.= '  <span class="fn n">' . "\n    <span class='given-name'>$this->first_name</span> <span class='family-name'>$this->last_name</span>\n  </span>\n";
		}elseif(($this->first_name || $this->last_name) && $reverse){
			$show_name.="  <span class='fn n'>\n    <span class='family-name'>$this->last_name</span>, <span class='given-name'>$this->first_name</span>\n  </span>\n";
		}
		
		if(($this->first_name_2 || $this->last_name_2) && !$reverse){
			$show_name.="  <span class='secondary'>$this->first_name_2 $this->last_name_2</span>\n";
		}elseif(($this->first_name_2 || $this->last_name_2) && !$reverse){
			$show_name.="  <span class='secondary'>$this->last_name_2, $this->first_name_2</span>\n";
		}
    
		if($this->business_name && ($reverse !== null && $reverse === true)){
			$show_name.='  <span class="org">' . $this->business_name."</span>\n";
		}
		
		return $show_name;

	}
	
	/*******
	 * string outputMemberSearchResults(void) 
	 * an output function for the paginator, for searching for members with member search form
	 */
	
	function outputMemberSearchResults(){
		return "<tr>
					<td>$this->member_id</td>
					<td>
<div class='vcard'>
".$this->showName()."  <p>User Name:<span class='nickname'>$this->username_m</span></p>
  <p>email: <a class='email' href='mailto:" . $this->email_address . "'>" . $this->email_address . "</a></p>
</div>    </td>
					<td><a href='".SELF."?class=".base64_encode("memberSearchOutput")."&method=".base64_encode("printSingleMemberEditForm")."&member_id=$this->member_id'>Edit Member</a> 
					<a href = '".SELF."?class=".base64_encode("invoice")."&method=".base64_encode("buildInvoice")."&member_id=".$this->member_id."&delivery_id=".CURRENT_DELIVERY_ID."'>View current invoice</a>  
					<a href ='".SELF."?class=".base64_encode("member")."&method=".base64_encode("pastOrders")."&member_id=$this->member_id'>View Past Invoices</a> 
					<a href ='".SELF."?class=".base64_encode("basket")."&method=".base64_encode("showChangeDeliveryInfoForm")."&delivery_id=".CURRENT_DELIVERY_ID."&member_id=$this->member_id'>Edit delivery info</a></td>
				 </tr>"; 
	}

	function outputMemberSearchResultsWithNumOrders($numOrders){
			return "<tr>
					<td>".$numOrders[$this->member_id]."</td>
					<td>$this->member_id</td>
					<td>".$this->showName()."</td>
					<td>$this->business_name</td>
					<td>$this->username_m</td>
					<td><a href='".SELF."?class=".base64_encode("memberSearchOutput")."&method=".base64_encode("printSingleMemberEditForm")."&member_id=$this->member_id'>Edit Member</a> 
					<a href = '".SELF."?class=".base64_encode("invoice")."&method=".base64_encode("buildInvoice")."&member_id=".$this->member_id."&delivery_id=".CURRENT_DELIVERY_ID."'>View current invoice</a>  
					<a href ='".SELF."?class=".base64_encode("member")."&method=".base64_encode("pastOrders")."&member_id=$this->member_id'>View Past Invoices</a> 
					<a href ='".SELF."?class=".base64_encode("basket")."&method=".base64_encode("showChangeDeliveryInfoForm")."&delivery_id=".CURRENT_DELIVERY_ID."&member_id=$this->member_id'>Edit delivery info</a></td>
				 </tr>"; 	
	}
		
	
	function outputLabelResults(){
		if($this->member_id){
			$display .= "Member ID: ".$this->member_id." ";
		}
		
		if($this->membership_date){
			$display .= "Membership Date: ".dateTools::parseDate($this->membership_date)." ";
		}
			
		$display.="<b>".$this->showName()."</b>";
		$display.=$this->showInfo();
		$display.="  ";	
		
		return $display;
	}
	
	/*****
	 * string showInfo(string delivery_type = null)
	 * Returns a formatted block of text with addresses, phone numbers, etc.
	 **/
	
	function showInfo($deltype=null){
		$this->delgtype=$deltype;
		
		if($this->ddeltype){
			$display_type=$this->deltype;
		}else{
			$display_type="aa";//all available info
		}
    
    $display .="<span class='adr'>\n";
		
		if($display_type=="W"){
			$display .= "<span class='type'>Work</span> address:";
  			if ($this->work_address_line1){
				$display .= "<div class='street-address'>$this->work_address_line1</div>\n"; 
			}else{ 
				$display .= "No work address available";
			}
  
  			if ($this->work_address_line2){ 
				$display .= "<div class='extended-address'>$this->work_address_line2</div>\n";
			}
			
			if ($this->work_city || $this->work_state || $this->work_zip){
				$display .= "<div><span class='locality'>$this->work_city</span> <span class='region'>$this->work_state</span>, <span class='postal-code'>$this->work_zip</span></div>";
			}
		}elseif($display_type!="aa"){
			$display .= "<span class='type'>Home</span> address:";
			$display .= "<div class='street-address'>$this->address_line1</div>\n";
			if ($this->address_line2){ 
				$display .= "<div class='extended-address'>$this->address_line2</div>\n";
			}
			
			$display .= "<div><span class='locality'>$this->city</span> <span class='region'>$this->state</span>, <span class='postal-code'>$this->zip</span></div>\n";
		}elseif($display_type=="aa"){
			$display .= "<span class='type'>Home</span> address:";
			if($this->address_line1){
				$display .= "<div class='street-address'>$this->address_line1</div>\n";
			}

			if($this->address_line2){
        $display .= "<div class='extended-address'>$this->address_line2</div>\n";
			}
			
			if($this->city){
				$display .= "<div><span class='locality'>$this->city</span> <span class='region'>$this->state</span>, <span class='postal-code'>$this->zip</span></div>\n";
      }
		}
    $display .= "</span>\n";
		
		if ($this->email_address){
			$display .= "<a class='email' href='mailto:".$this->email_address."'><abbr class='type' title='pref'>(preferred)</abbr> ".$this->email_address."</a>";
		}

		if ($this->email_address_2){
			$display .= "<a class='email' href='mailto:".$row['email_address_2']."'>".$this->email_address_2."</a>\n"; 
		}
		
		if ($this->home_phone){ 
			$display .= "<span class='tel'><span class='value'>$this->home_phone</span> (<span class='type'>home</span>)</span>\n"; 
		}
		
		if ($this->work_phone){ 
			$display .= "<span class='tel'><span class='value'>$this->work_phone</span> (<span class='type'>work</span>)</span>\n";
		}
		
		if ($this->mobile_phone){
			$display .= "<span class='tel'><span class='value'>$this->mobile_phone</span> (<span class='type'>cell</span>)</span>\n"; 
		}
	
		if ($this->fax){ 
			$display .= "<span class='tel'><span class='value'>$this->fax</span> (<span class='type'>fax</span>)</span>\n";
		}
    
		return $display;
	}
	
	//retrieves member info in order to call the add member form.  The form call should be in another function
	/************* HOLDING OFF editing THIS UNTIL IT CAN BE INTEGRATED WITH EMMA'S NEW VERSION********/
	function updateInfo($id=null){
				
		if($_REQUEST[ID]){
			$id=$_REQUEST[ID];
			$action = "edit";
		}elseif($_REQUEST['member_id']){
			$id=$_REQUEST['member_id'];
			$action = "edit";
		}elseif(!$_REQUEST[ID]){
			$action = "edit";
		}else{
			$action = "add";
		}
		
		//an extra layer of security
		if(Security::getRegisteredAuthType()!="administrator"){
			if($id!=Security::getRegisteredMemberId())
			{
				die("You do not have permission to edit this information.<a href='".SELF."'>Back to Main Page</a>");
			}
		
		}
				
		$sql_m="SELECT * FROM ".TABLE_MEMBER." WHERE 'member_id'=".$id;
		$query_m=mysql_query($sql_m, MYSQL_CONN) or die(mysql_error()."::$sql_m");	
		$result=mysql_fetch_array($query_m);
		
    mysql_free_result($query_m);
				
		include DIR_FORMS."addmember.form.php";
		return;
	
	}
	
	/*****
	 * boolean checkMemberForm(void)
	 * - Validates add/edit member form. Returns errors and a list of marked fields and rebuilds form on failure.
	 * On success it calls the method to store the data.
	 */ 
	
	function checkMemberForm(){
		
		$fields=array();
		$cf=new formValidator;
		
		$fields["first_name"]=$cf->checkText($_POST[first_name], "first name");
		$fields["last_name"]=$cf->checkText($_POST[last_name], "last name");
		
		if($_POST[first_name_2] || $_POST[last_name_2]){
			$fields["first_name_2"]=$cf->checkText($_POST[first_name_2], "first name 2");
			$fields["last_name_2"]=$cf->checkText($_POST[last_name_2], "last name 2");
		}else{//for the optional fields, if they didn't enter a value in the first place, we won't mark it. if they entered a value and it was bad, well then we have a problem
			$fields["first_name_2"]=true;
			$fields["last_name_2"]=true;
		}
		
		if($_POST[email_address]){
			$fields["email_address"]=$cf->validateEmail($_POST[email_address]);
		}else{// see above
			$fields["email_address"]=true;
		}
		
		if($_POST[email_address_2]){
			$fields["email_address_2"]=$cf->validateEmail($_POST[email_address_2]);
		}else{//see above
			$fields["email_address_2"]=true;
		}
		
		$fields["home_phone"]=$cf->checkText($_POST[home_phone], "home phone");
		$fields["address_line1"]=$cf->checkText($_POST[address_line1], "address");
		$fields["city"]=$cf->checkText($_POST[city], "city");
		$fields["state"]=$cf->checkText($_POST[state], "state");
		$fields["zip"]=$cf->checkText($_POST[zip], "zip");		
					
		$fields["username_m"]=$cf->checkText($_POST[username_m], "user name");
		
		if($fields["username_m"]){
			if(!$_REQUEST["member_id"]){
				$sql="SELECT * FROM ".TABLE_MEMBER." WHERE username_m = '".$_REQUEST['username_m']."';";
				$query=mysql_query($sql, MYSQL_CONN) or die(mysql_error()."$sqlmember::checkMemberForm()");
				$rows=@mysql_num_rows($query);
		
				if($rows>0){
					$fields["username_m"]=$cf->addError("There is already a user with this username. Please choose a different one.");
				}
			}
		}
				
		if(!$_REQUEST["member_id"] || $_REQUEST[password_r]){
			
			if($fields["password"]=$cf->checkText($_POST[password], "password", "min", 6, 25, "alphanumeric") && $fields["password_r"]=$cf->checkText($_POST[password_r], "password again", "min", 6, 25, "alphanumeric")){
				if($_POST[password]!=$_POST[password_r]){
					$fields["password_r"]=$cf->addError("The second password does not match the first.");
				}
			}
		}
		
		if(!$cf->showErrors()){
			$row = array();
			$keys = array_keys($_POST);
			
			foreach($keys as $key){
				$row[$key] = $_POST[$key];	
			}
			
			$keys = array_keys($row);
			foreach($keys as $key){
				print $key."-".$row[$key];
			}
					
			$this->set($row, true);
			$this->member_id = $_REQUEST["member_id"];
				
			if($_REQUEST[producer_id]){
				$producer =& new producer();
				$producer->setById($_REQUEST["producer_id"]);
			}
			
			include DIR_FORMS."addmember.form.php";
			return false;
		}
		
		return $this->insertMemberData();
	}
	/*****
	 * boolean insertMemberData(void)
	 * - Stores data gathered from addMember.form
	 ****/
	
	function insertMemberData(){
		//whether or not to list the producer is the most common action, if the member is also a producer check to see whether we need to flip it					
		if($_REQUEST[producer_id])	{
			if(!$_REQUEST[donotlist_producer]){
				$donot=0;
			}else{
				$donot=1;
			}
			$sql="UPDATE ".TABLE_PRODUCER." SET 
				donotlist_producer=$donot
				WHERE member_id=$_GET[member_id]";
			
			$query=mysql_query($sql, MYSQL_CONN) or die(STANDARD_ERROR.mysql_error()."$sqlmember::insertMemberData");
					
		}
				
		 if(!$_REQUEST[password_r]){
			$password=$_REQUEST[password];
		 }
		 /*else{
		 	$query=mysql_query("SELECT PASSWORD('".$_POST[password]." as pass')", $this->conn) or die("$c->standard_error".mysql_error());
			$password=mysql_result($query, 0, "password");
		 }*/
				
		if($_REQUEST[no_postal_mail]!=1){
			$_REQUEST[no_postal_mail]=0;
		}
		
		if($_REQUEST[membership_discontinued]!=1){
			$_REQUEST[membership_discontinued]=0;
		}
		
		if($_REQUEST["member_id"]){
			
			$sql="UPDATE ".TABLE_MEMBER." SET 
			pending='$_POST[pending]',
			username_m='$_POST[username_m]',";
			if(!$password){
				$sql.= "password=PASSWORD('$_POST[password]'), ";
			}
			$sql.="business_name='$_POST[business_name]',
			last_name='$_POST[last_name]',
			first_name='$_POST[first_name]',
			last_name_2='$_POST[last_name_2]',
			first_name_2='$_POST[first_name_2]',
			no_postal_mail='$_POST[no_postal_mail]',
			address_line1='$_POST[address_line1]',
			address_line2='$_POST[address_line2]',
			city='$_POST[city]',
			state='$_POST[state]',
			zip='$_POST[zip]',
			county='$_POST[county]',
			work_address_line1='$_POST[work_address_line1]',
			work_address_line2='$_POST[work_address_line2]',
			work_city='$_POST[work_city]',
			work_state='$_POST[work_state]',
			work_zip='$_POST[work_zip]',
			email_address='$_POST[email_address]',
			email_address_2='$_POST[email_address_2]',
			home_phone='$_POST[home_phone]',
			work_phone='$_POST[work_phone]',
			mobile_phone='$_POST[mobile_phone]',
			fax='$_POST[fax]',
			toll_free='$_POST[toll_free]',
			home_page='$_POST[home_page]',
			memb_amt_owed='$_POST[memb_amt_owed]',
			membership_date='$_POST[membership_date]',
			mem_taxexempt='$_POST[mem_taxexempt]',
			membership_discontinued='$_POST[membership_discontinued]',
			how_heard_id = '{$_REQUEST['how_heard_id']}',
			auth_type='{$_REQUEST['auth_type']}'
			WHERE member_id=".$_REQUEST['member_id'];
					
		}else{
			$sql="INSERT INTO ".TABLE_MEMBER." values('','$_POST[pending]','$_POST[username_m]', PASSWORD('$_POST[password]'),'{$_REQUEST['auth_type']}','$_POST[business_name]',
			'$_POST[last_name]','$_POST[first_name]','$_POST[last_name_2]', '$_POST[first_name_2]',
			'$_POST[no_postal_mail]','$_POST[address_line1]','$_POST[address_line2]','$_POST[city]','$_POST[state]',
			'$_POST[zip]','$_POST[county]','$_POST[work_address_line1]','$_POST[work_address_line2]',
			'$_POST[work_city]','$_POST[work_state]','$_POST[work_zip]','$_POST[email_address]',
			'$_POST[email_address_2]','$_POST[home_phone]','$_POST[work_phone]','$_POST[mobile_phone]','$_POST[fax]',
			'$_POST[toll_free]', '$_POST[home_page]','$_POST[memb_amt_owed]',
			'$_POST[membership_date]','$_POST[mem_taxempt]', '$_POST[membership_discontinued]', '$_POST[mem_delch_discount]', '{$_REQUEST['how_heard_id']}');";
		}
		
		$query=mysql_query($sql, MYSQL_CONN) or die(STANDARD_ERROR.mysql_error()."$sql member::insertMemberData");
		
		$sql="SELECT member_id FROM ".TABLE_MEMBER." WHERE username_m='$_POST[username_m]';";
    $query=mysql_query($sql, MYSQL_CONN) or die(STANDARD_ERROR.mysql_error().":::$sql member::insertMemberData()");
			
		$member_id=mysql_result($query, 0, "member_id");
    
    if($_REQUEST[new_producer_id]){
							
			$sql="INSERT INTO ".TABLE_PRODUCER ."
			(producer_id, member_id,  donotlist_producer) 
			values('$_POST[new_producer_id]','$member_id', '$_POST[donotlist_producer]');";
			$query=mysql_query($sql, MYSQL_CONN) or die(STANDARD_ERROR.mysql_error()." member::insertMemberData())");
		}
		
		if($query && $_REQUEST["member_id"]){
			$_SESSION['message']="Member updated! ";
		}else{
			$_SESSION['message']="Member added! ";
		}
    
    rssLog::logEvent(array('member_id'=>$member_id, 'what'=>"'contact'", 'on_id'=>$member_id),TABLE_RSS_UPDATES);
		
		if(nav::jumpPointExists("insertMemberData")){
			nav::jumpToPoint("insertMemberData", SELF);
		}else{
			$obj = new menus;
			$obj->mainMenu();
		}
		
		return true;
	}
	
				
	function pastOrders(){
		$this->setById($_REQUEST['member_id']);
			
		$basket = new basket;
		
		//$basket_id = $basket->setBasketID($this->member_id);
			
		$show_name="user ".$this->username_m;
		
		$sql = "SELECT ".TABLE_BASKET_ALL.".*, 
				".TABLE_DELDATE.".*
				FROM ".TABLE_BASKET_ALL."
				LEFT JOIN ".TABLE_DELDATE." USING (delivery_id)
				WHERE ".TABLE_BASKET_ALL.".member_id = $this->member_id 
				AND ".TABLE_BASKET_ALL.".delivery_id <= ".CURRENT_DELIVERY_ID."
				ORDER BY ".TABLE_BASKET_ALL.".delivery_id DESC";
				
		
		$rs = mysql_query($sql,MYSQL_CONN) or die(mysql_error().":::$sql");
		$rows = @mysql_num_rows($rs);

		//if there are orders
		if($rows!=0){
			$display.="<ul>";
			while ($row = mysql_fetch_array($rs))
			{ 
				$delivery_id = $row['delivery_id'];
				$delivery_date = $row['delivery_date'];
				$basket_id =$row['basket_id'];
				$display .="<li /> <a href='".SELF."?class=".base64_encode("invoice")."&method=".base64_encode("printStoredInvoice")."&delivery_id=$delivery_id&member_id=$this->member_id&basket_id=$basket_id'>".dateTools::parseDate($delivery_date)."</a> ";
		
			}
			$display.="</ul>";
		}else{
			$display="<span class='maroonText'>There are no past orders with this username.</span>";
		}
		echo "<div align='center'>";
		echo "<table width='60%'>";
		echo "<tr>";
		echo "<td align='left'><h3>Previous Orders for $show_name</h3>";
		echo "$display";
		echo "</td></tr></table>";
		echo "</div>";
		
		return;
	}//end invoice::pastOrders
	
	function outputForInvoiceSearch($argumentArray){
		$invoice =& new invoice();
		$basket =& new basket();
		
		foreach($argumentArray as $key => $arg){
			$$key = $arg;
		}
		
		$basket_id = $basket->setBasketId($this->member_id, $delivery_id);
		$numItems = $basket->getNumItemsInBasket($delivery_id, $basket_id);
		
/*		$invoice->getBasketInfo($this->member_id, $basket_id, $delivery_id);
		$subtotal = $invoice->total + $invoice->total_exempt;
		
		$invoice->getAdjustmentInfo($basket_id);
		$subtotal += $invoice->adj_total + $invoice->adj_total_exempt;*/
		
		$finalized = $invoice->isFinalized($basket_id, $delivery_id);
		$output = "<tr>";
		
		
				
		$output .= "<td>$this->member_id</td><td align='left'>";
				
		if($finalized==0){
			$output .= "<a href='".SELF."?class=".base64_encode("invoice")."&method=".base64_encode("buildInvoice")."&basket_id=$basket_id&delivery_id=$delivery_id&member_id=$this->member_id'>".$this->showName("reverse")."</a></td><td>Not Finalized</td>";
		}else{
			$output .= $this->showName("reverse")."</td><td>Finalized</td>";
		}	
		
		if($numItems==0 && $this->adj_id>0){
			$output .= "<td>adj. only</td>";
		}else{
			$output .= "<td>".$numItems."</td>";
		}
		
		$output .= "<td>\$".$subtotals[$this->member_id]."</td>";

		$routeConfirmed = $basket->isRouteConfirmed($basket_id);
		if($routeConfirmed==1){
			$routeConfirmed="Yes";
		}else{
			$routeConfirmed="No";
		}

		$invoice->setDelVars($basket_id, $delivery_id);			
		$output .= "<td class='".Delivery::getHubColor($invoice->hub)."'>$routeConfirmed / $invoice->hub</td>";
		
		$output .= "<td>";
		
		if($finalized) 
			$output .= "<a href='".SELF."?class=".base64_encode("memberSearchOutput")."&method=".base64_encode("unfinalizeOrder")."&basket_id=$basket_id&invoice_exists=1&delivery_id=$delivery_id'>Unfinalize to edit</a>";
					
		$output .= "</td></tr>";
		
		return $output;
	}
	
	function outputMembersWithPrintSubscriptions(){
		$monthsLeft = 3 - (CURRENT_DELIVERY_ID-$this->delivery_id);
		if($monthsLeft > 0){
			$output.= $this->showName();
			$output.= $this->showInfo();
			$output.= "Signed up during <b>".dateTools::parseDate($this->order_date)."</b> order cycle should receive <b>$monthsLeft</b> more mailings.  ";
		}	
			
		
		return $output;
	}
	
	/****
	 * boolean outputEditMemberForm(producer member_producer_info=null)
	 * -Prints the add member form with or without preexisting data.  Optional argument
	 * is a producer objet containing the member's producer info
	 */
	
	function outputEditMemberForm($producer=null){//optionally, the member's producer information
		include DIR_FORMS."addmember.form.php";
		return true;
	}
	
	function viewOrdersHistory(){
		$member_id = $_REQUEST['member_id'];
		
		$sql = "SELECT * FROM ".TABLE_MEMBER."
				LEFT JOIN ".TABLE_BASKET_ALL." USING (member_id)
				LEFT JOIN ".TABLE_DELDATE." USING (delivery_id)
				WHERE ".TABLE_BASKET_ALL.".finalized = 1 AND
				".TABLE_MEMBER.".member_id = $member_id
				ORDER BY ".TABLE_BASKET_ALL.".delivery_id DESC";
		
		$result = mysql_query($sql, MYSQL_CONN) or die(STANDARD_ERROR.mysql_error().$sql);
		$member=& new member();
		$member->setById($member_id);
		print "<h2>Order Totals for member #$member_id:  ".$member->showName()."</h2>";
		print "<table>";
		print "<tr><td>Delivery Date</td><td>Order total</td></tr>";
		
		while($row = mysql_fetch_array($result)){
			print "<tr>
					<td>".dateTools::parseDate($row['delivery_date'])."</td>
					<td>$".number_format($row['grand_total'],2)."</td>
				   </tr>";
			
		}
		print "</table>";
		
		
	}
  
}

?>